using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;
using System.Data.SqlClient;


namespace Presentation
{
    public partial class frmTimKiem : Form
    {
        int flag = 0;
        public frmTimKiem()
        {
            InitializeComponent();
        }

        private void rdbThongThuon_Click(object sender, EventArgs e)
        {
            flag = 1;
            lblTenKH.Visible = false; 
            lblDC.Visible = false;
            lblDT.Visible = false;
            txtTen.Visible = false;
            txtDienThoai.Visible = false;
            txtDiaChi.Visible = false;
            txtMa.Visible = true;
            cbbMaKH.Visible = true;
        }

        private void rdbNangCao_Click(object sender, EventArgs e)
        {
            flag = 2;
            lblTenKH.Visible = true;
            lblDC.Visible = true;
            lblDT.Visible = true;
            txtTen.Visible = true;
            txtDienThoai.Visible = true;
            txtDiaChi.Visible = true;
            txtMa.Visible = false;
            cbbMaKH.Visible = false;
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void frmTimKiem_Load(object sender, EventArgs e)
        {
            KhachHangDTO[] arr = new KhachHangDTO[100];
            KhachHangBUS khBUS = new KhachHangBUS();
            arr = khBUS.LayDanhSachKH();
            cbbMaKH.ValueMember = "MaKH";
            cbbMaKH.DisplayMember = "MaKH";
            cbbMaKH.DataSource =arr;
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            KhachHangBUS khBUS = new KhachHangBUS();
            KhachHangDTO kh = new KhachHangDTO();
            KhachHangDTO[] arr = new KhachHangDTO[100];
            if (flag == 1)
            {
                kh.MaKH = Convert.ToInt32(cbbMaKH.SelectedValue);
                arr = khBUS.TimKiemKhachHang(kh.MaKH);
                dtgvDSKH.DataSource = arr;
            }
            if (flag == 2)
            {
                kh.TenKH = txtTen.Text;
                kh.DienThoai = txtDienThoai.Text;
                kh.DiaChi = txtDiaChi.Text;
                arr = khBUS.TimKiemNangCao(kh);
                dtgvDSKH.DataSource = arr;
            }
        }

    }
}